using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;


namespace Cassandraemon.FullText
{

	public class NormalAnalyzer : IAnalyzer
	{
		public NormalAnalyzer ()
		{
		}

		public Dictionary<string, List<int>> MakeRegsitData(string text)
		{
			var t = text.ToLower().Normalize();
			
			var result = new Dictionary<string, List<int>>();
			
			var array = Regex.Split(t, "\\W", RegexOptions.Compiled);
				
			var list = array.Except(new []{ "" }).Distinct().ToList();
			
			foreach(string item in list)
			{
				result.Add(item, new List<int>());
				
				for(int i=0; i<array.Length; i++)
				{
					if(item == array[i])
					{
						result[item].Add(i);
					}
				}
			}
			
			return result;
		}
		
		public List<string> SplitQueryPhrase (string phrase)
		{
			var t = phrase.ToLower().Normalize();
			
			var array = Regex.Split(t, "\\W", RegexOptions.Compiled);
			
			return array.Except(new []{ "" }).ToList();
		}
		
	}
}
